import { Directive,Input,ElementRef,Renderer,HostListener } from '@angular/core';

@Directive({
  selector: '[appBgcolor]'
})
export class BgcolorDirective {
    private _defaultColor='yellow'
    @Input('appBgcolor')
    backgroundColor:string
    constructor(private ElementRef:ElementRef,private Renderer:Renderer) { }

    setColor(color:string){
        this.Renderer.setElementStyle(this.ElementRef.nativeElement,'backgroundColor',color)
    }

    @HostListener('click')
    onclick(){
        this.setColor(this.backgroundColor||this._defaultColor)
    }


}
